package com.anolesoft.yr.mbus.contm.service.impl;

import com.anolesoft.yr.mbus.contm.entity.ContmBaseClause;
import com.anolesoft.yr.mbus.contm.entity.ContmContent;
import com.anolesoft.yr.mbus.contm.service.ContmContentService;
import org.springframework.stereotype.Service;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.anolesoft.yr.mbus.contm.entity.ContmContentExample;
import com.anolesoft.yr.mbus.contm.dao.ContmContentDao;

@Service
public class ContmContentServiceImpl extends ServiceImpl<ContmContentDao, ContmContent> implements ContmContentService {

    @Override
    public long countByExample(ContmContentExample example) {
        return baseMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(ContmContentExample example) {
        return baseMapper.deleteByExample(example);
    }

    @Override
    public List<ContmContent> selectByExample(ContmContentExample example) {
        return baseMapper.selectByExample(example);
    }

    @Override
    public int updateByExampleSelective(ContmContent record, ContmContentExample example) {
        return baseMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(ContmContent record, ContmContentExample example) {
        return baseMapper.updateByExample(record, example);
    }

    @Override
    public int updateBatch(List<ContmContent> list) {
        return baseMapper.updateBatch(list);
    }

    @Override
    public int batchInsert(List<ContmContent> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public int insertOrUpdate(ContmContent record) {
        return baseMapper.insertOrUpdate(record);
    }

    @Override
    public int insertOrUpdateSelective(ContmContent record) {
        return baseMapper.insertOrUpdateSelective(record);
    }



    @Override
    public void pageInsertBatch(List<ContmContent> contmContents){
        for (int i = 0; i < contmContents.size(); i++) {

            if ( contmContents.get(i)!=null&&contmContents.get(i).getContmContents()!=null)
            {
                saveExecute(contmContents.get(i), contmContents.get(i).getPageType());
            }
        }

    }

    private void saveExecute(ContmContent contmContent,String pageType){
        contmContent.setPageType(pageType);
        save(contmContent);
        if (contmContent.getContmContents()!=null){
            contmContent.getContmContents().forEach(a->{
                saveExecute(a,pageType);
            });
        }
    }
}

